package com.monitor.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.monitor.common.annotation.Log;
import com.monitor.common.core.controller.BaseController;
import com.monitor.common.core.domain.AjaxResult;
import com.monitor.common.enums.BusinessType;
import com.monitor.system.domain.NodeUsage;
import com.monitor.system.service.INodeUsageService;
import com.monitor.common.utils.poi.ExcelUtil;
import com.monitor.common.core.page.TableDataInfo;

/**
 * 备份节点Controller
 * 
 * @author monitor
 * @date 2024-06-11
 */
@RestController
@RequestMapping("/system/usage")
public class NodeUsageController extends BaseController
{
    @Autowired
    private INodeUsageService nodeUsageService;

    /**
     * 查询备份节点列表
     */
    @ApiOperation("查询备份节点列表")
//    @PreAuthorize("@ss.hasPermi('system:usage:list')")
    @GetMapping("/list")
    public TableDataInfo list(NodeUsage nodeUsage)
    {
        startPage();
        List<NodeUsage> list = nodeUsageService.selectNodeUsageList(nodeUsage);
        return getDataTable(list);
    }

    /**
     * 导出备份节点列表
     */
    @PreAuthorize("@ss.hasPermi('system:usage:export')")
    @Log(title = "备份节点", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, NodeUsage nodeUsage)
    {
        List<NodeUsage> list = nodeUsageService.selectNodeUsageList(nodeUsage);
        ExcelUtil<NodeUsage> util = new ExcelUtil<NodeUsage>(NodeUsage.class);
        util.exportExcel(response, list, "备份节点数据");
    }

    /**
     * 获取备份节点详细信息
     */
    @ApiOperation("获取备份节点详细信息")
    @PreAuthorize("@ss.hasPermi('system:usage:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(nodeUsageService.selectNodeUsageById(id));
    }

    /**
     * 新增备份节点
     */
    @ApiOperation("新增备份节点")
    @PreAuthorize("@ss.hasPermi('system:usage:add')")
    @Log(title = "备份节点", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody NodeUsage nodeUsage)
    {
        return toAjax(nodeUsageService.insertNodeUsage(nodeUsage));
    }

    /**
     * 修改备份节点
     */
    @ApiOperation("修改备份节点")
    @PreAuthorize("@ss.hasPermi('system:usage:edit')")
    @Log(title = "备份节点", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody NodeUsage nodeUsage)
    {
        return toAjax(nodeUsageService.updateNodeUsage(nodeUsage));
    }

    /**
     * 删除备份节点
     */
    @ApiOperation("删除备份节点")
    @PreAuthorize("@ss.hasPermi('system:usage:remove')")
    @Log(title = "备份节点", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(nodeUsageService.deleteNodeUsageByIds(ids));
    }
}
